package spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AspectHandler {

    @Pointcut("execution(* maven.jyhs.com.*.*(..))")
    public void pointcut() {}
    @Before("pointcut()")
    public void beforeAdvice(JoinPoint jp) {
        System.out.println("调用+"+jp.getTarget()+"的"+jp.getSignature().getName()+"方法.方法入参："+jp.getArgs());
    }

    public  void  afterAdvice(){
        System.out.println("After Advice");
    }
    public  void afterReturningAdvice(JoinPoint jp, Object ret){
        System.out.println("调用+"+jp.getTarget()+"的"+jp.getSignature().getName()+"方法.方法返回值："+ret);
    }
    @Around("execution(* maven.jyhs.com.*.*(..))")
    public Object aroundAdvice(ProceedingJoinPoint jp) {

        System.out.println("环绕通知：调用 " + jp.getTarget() + " 的 " + jp.getSignature().getName()
                + " 方法。");
        Object result = null;
        try {
            result = jp.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("方法返回：" + result);
        return  result;
    }
}
